package com.stfalcon.chatkit.sample.features.demo;

import android.app.Activity;
import android.os.Bundle;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.EditText;

import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.stfalcon.chatkit.sample.R;
import com.stfalcon.chatkit.sample.adapter.UserSearchAdapter;
import com.stfalcon.chatkit.sample.common.data.model.User;
import com.stfalcon.chatkit.sample.listenser.UserSearchListener;

import org.jetbrains.annotations.NotNull;

import java.util.ArrayList;
import java.util.List;

/**
 * 搜索
 */
public class UserSearchActivity extends Activity {

    private EditText userName;

    private UserSearchAdapter userSearchAdapter;

    public List<User> getUserList() {
        return userList;
    }

    private RecyclerView recyclerView;

    public void setUserList(List<User> userList) {
        this.userList = userList;

        this.userSearchAdapter.setItems(userList);
    }

    private List<User> userList;

    protected void onCreate(@NotNull Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        this.setContentView(R.layout.activity_search_user);

        this.recyclerView = findViewById(R.id.recyclerViewUserSearch);

        this.recyclerView.setLayoutManager(new LinearLayoutManager(this));

        this.userList = new ArrayList<User>();

        userSearchAdapter = new UserSearchAdapter(this, userList);

        this.recyclerView.setAdapter(userSearchAdapter);

        this.userName = findViewById(R.id.user_data);


        this.initListener();

    }

    protected void initListener()
    {
        this.userName.addTextChangedListener(new UserSearchListener(userName, this));

        this.userName.setOnFocusChangeListener(new View.OnFocusChangeListener() {



            @Override
            public void onFocusChange(View v, boolean hasFocus) {



                if (userName.getText().toString().equals("搜索")) {
                    userName.setText("");
                }
            }
        });

    }

}


